import { createApp } from 'vue';
import './plugins/assets';
import VueUeditorWrap from 'vue-ueditor-wrap';
import { localStg } from '@/utils/storage';
import { getObjectWithScene } from '@/utils/utils';
import { setupDayjs, setupIconifyOffline, setupLoading, setupNProgress } from './plugins';
import { setupStore } from './store';
import { setupRouter } from './router';
import { setupI18n } from './locales';
import App from './App.vue';
import '@/styles/scss/fonts.scss';

async function setupApp() {
  setupLoading();

  setupNProgress();

  setupIconifyOffline();

  setupDayjs();

  const app = createApp(App);

  if (import.meta.env.DEV) {
    console.log("开发环境呀")
    // const toeknStr: string = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjA2YzAzMTI1LTQ0ZjktNGY2OS1iMjNkLTM1MmE2MTVjMjcxNCJ9.cqnnIDJ4Ms1EQhWLpC6QTcg_9RlTZhLBYZcoNEoU7rCcpG48h0MvHMUmbAx_NZN7VgCcH48JhRQgLhX1SF7C0g';
    // localStg.set('token', toeknStr);
    // localStg.set('refreshToken', `refreshToken${toeknStr}`);
    // localStg.set('moduleId', 1);
  } else {
    const url = window.location.href;
    console.log('url: ', url);
    const startIndex: number = url.indexOf('?');
    // const newUrl: string = url.substring(startIndex);
    // const newStartIndex: number = newUrl.indexOf('?');
    const queryStr: string = url!.substring(startIndex + 1);
    const queryObj: any = getObjectWithScene(queryStr);
    if (queryObj.token) {
      // console.log('token: ', queryObj.token);
      localStg.set('token', queryObj.token);
      localStg.set('refreshToken', `refreshToken${queryObj.token}`);
      localStg.set('moduleId', queryObj.moduleId);
    }

    // 去除正式环境的日志信息
    if (window) {
      window.console.log = () => {};
    }
  }

  setupStore(app);

  await setupRouter(app);

  setupI18n(app);

  app.use(VueUeditorWrap);

  // setupAppVersionNotification();

  app.mount('#app');
}

setupApp();
